#include "spherizedialog.h"
#include "ui_spherizedialog.h"

#include <QPainter>

SpherizeDialog::SpherizeDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SpherizeDialog)
{
    ui->setupUi(this);

    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & ~Qt::WindowMinimizeButtonHint);
    setWindowTitle(tr("Spherize"));
    setModal(true);
    setFixedSize(343, 128);

    connect(ui->heightSlider, SIGNAL(valueChanged(int)), ui->heightSpinBox, SLOT(setValue(int)));
    connect(ui->heightSpinBox, SIGNAL(valueChanged(int)), this, SLOT(emitHeightChanged(int)));
    connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked()));
    connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
}

SpherizeDialog::~SpherizeDialog()
{
    delete ui;
}

void SpherizeDialog::setHeight(int height)
{
    ui->heightSpinBox->setValue(height);
}

void SpherizeDialog::setHeightMaximum(int max)
{
    ui->heightSlider->setMaximum(max);
    ui->heightSpinBox->setMaximum(max);
}

void SpherizeDialog::emitHeightChanged(int height)
{
    ui->heightSlider->setValue(height);
    emit heightChanged(height);
}

void SpherizeDialog::applyButtonClicked()
{
    QString str = tr("Spherize Filter. Height : ")
            + QString::number(ui->heightSlider->value()) + tr(".");
    emit applyOperator(str);
    close();
}

void SpherizeDialog::cancelButtonClicked()
{
    close();
}

void SpherizeDialog::closeEvent(QCloseEvent *)
{
    emit cancelOperator();
}

void SpherizeDialog::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setPen(Qt::gray);
    painter.drawRect(10, 10, width() - 20, height() - 20);
}
